package cn.com.dycc.topic_activity.controller;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.topic_activity.param.Pb_Activity_ResultParam;
import cn.com.dycc.topic_activity.service.Pb_Activity_ResultService;
import cn.com.dycc.topic_activity.service.Pb_Special_ActivityNotFoundException;
import cn.com.dycc.util.JsonObjectResult;


@Controller
@RequestMapping("/topic_activity/pb_activity_result")
public class Pb_Activity_ResultController extends BaseController{

	@Resource
	private Pb_Activity_ResultService pb_Activity_ResultService;
	
	/**
	 * 新增专题活动成果汇报信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addPd_Activity_Result(Pb_Activity_ResultParam param,HttpSession session,HttpServletRequest request){
		
		int d=pb_Activity_ResultService.addPb_Activity_Result(param,request);
		String flag="成功导入数据条数为:"+d;
		return new JsonObjectResult(flag);		
	}
	
	/**
	 * 删除专题活动成果汇报信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deletePb_Activity_Result(HttpServletRequest request){
		String []attrStrs=request.getParameterValues("result_id");
		int d=pb_Activity_ResultService.deletePb_Activity_Result(attrStrs,request);
		String flag="成功删除数据条数为:"+d;
		return new JsonObjectResult(flag);
	}
	
	/**
	 * 查看自己发起的专题活动成果汇报信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/list.do")
	@ResponseBody
	public JsonObjectResult findPb_Activity_Result(Pb_Activity_ResultParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		String id=(String)session.getAttribute("id");
		param.setActivity_send_user(id);
		
		JsonObjectResult result=pb_Activity_ResultService.findPb_Activity_ResultByParam(param,request);
		
		return result;
	}
	
	/**
	 * 查询有关自己所属党组织及子孙节点的党组织的专题活动成果汇报信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/listAll.do")
	@ResponseBody
	public JsonObjectResult findAllPb_Activity_Result(Pb_Activity_ResultParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		param.setLeader_flag("1");
		
		JsonObjectResult result=pb_Activity_ResultService.findPb_Activity_ResultByParam(param,request);
		
		return result;
	}
	
	/**
	 * 查看专题活动成果汇报详情
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/detail.do")
	@ResponseBody
	public JsonObjectResult findDetailPb_Activity_Result(Pb_Activity_ResultParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		
		if(param.getActivity_id()==null||param.getActivity_id().trim().isEmpty()){
			throw new Pb_Special_ActivityNotFoundException("专题活动id不能为空");
		}
		JsonObjectResult result=pb_Activity_ResultService.findPb_Activity_ResultByParam(param,request);
		
		return result;
	}
	
}
